package com.xjj.servicejob.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xjj.entity.Img;
import com.xjj.entity.Job;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author sjy
 * @create 2022-10-20 11:38
 * 发布作业图片Mapper
 */
public interface JobPhotoMapper{
    /**
     * 添加发布作业的图片
     * @param jobPhotos
     */
    @Insert({"<script>" +
            "insert into xjj_job_photo(job_id,url) values" +
            "<foreach collection='jobPhotos' item='img' separator=','>" +
            "(#{img.relationalId},#{img.url})" +
            "</foreach>" +
            "</script>"})
    void insert(@Param("jobPhotos") List<Img> jobPhotos);

    /**
     * 删除发布的作业的图片
     * @param ids
     * @param jobId
     */
    @Delete({"<script>" +
            "delete from xjj_job_photo where id in" +
            "<foreach collection='ids' item='id'  open='('  separator=','  close=')'>" +
            "#{id}" +
            "</foreach>" +
            "and job_id =#{jobId}" +
            "</script>"})
    void delete(@Param("ids") List<Integer> ids, @Param("jobId") Integer jobId);

    /**
     * 获取改作业的所有图片
     * @param jobId
     * @return
     */
    @Select("select * from xjj_job_photo where job_id =#{jobId}")
    @Results(
            id = "JobPhotoMapper",
            value = {
                    @Result(column = "id", property = "id", id = true),
                    @Result(column = "job_id", property = "relationalId"),
                    @Result(column = "url", property = "url")
            }
    )
    List<Img> getAllImgByJobId(Integer jobId);

//    /**
//     * 根据id删除图片
//     * @param id
//     */
//    @Delete("delete from xjj_job_photo where id = #{id}")
//    void deleteJobPhotoById(Integer id);
}
